//顺序表的合并
#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct Node {
	ElemType data;
	struct Node * next;
}LinkNode,*LinkList;
LinkNode * CreateFormHead(){
	LinkList head;
	LinkNode * p;
	char flag;
	head =(LinkList)malloc(sizeof(LinkNode));
	head->next=NULL;
	flag='y';
	while(flag=='y'){
		p=(LinkNode *)malloc(sizeof(LinkNode));
		printf("请输入节点数据：");
		scanf_s("%d",&p->data);
		p->next=head->next;
		head->next=p;
		getchar();
		printf("继续输入吗？(y/n)");
		scanf("%c",&flag);
	}
	return head;
}
void OutputNode(LinkList head){
	LinkNode * s;
	s=head->next;
	while(s!=NULL){
		printf("%d ",s->data);
		s=s->next;
	}
	printf("\n");
}
int main(){
	LinkList head,head1,head2;
	LinkNode *p,*s,*r;
	int min;
	head =(LinkList)malloc(sizeof(LinkNode));
	head->next=NULL;
	head1=CreateFormHead();
	head2=CreateFormHead();
	s=head1->next;
	r=head2->next;
	while(s!=NULL&&r!=NULL){
		if(s->data<=r->data){
			p=(LinkNode *)malloc(sizeof(LinkNode));
			p->data=s->data;
			p->next=head->next;
			head->next=p;
			s=s->next;
		}
		else{
			p=(LinkNode *)malloc(sizeof(LinkNode));
			p->data=r->data;
			p->next=head->next;
			head->next=p;
			r=r->next;
		}
	}
	if(s==NULL){
		while(r!=NULL){
			p=(LinkNode *)malloc(sizeof(LinkNode));
			p->data=r->data;
			p->next=head->next;
			head->next=p;
			r=r->next;
		}
	}
	else{
		while(s!=NULL){
			p=(LinkNode *)malloc(sizeof(LinkNode));
			p->data=s->data;
			p->next=head->next;
			head->next=p;
			s=s->next;
		}
	}
	OutputNode(head1);
	OutputNode(head2);
	OutputNode(head);
	return 0;
}
